package com.example.businesscalcproject;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class Depreciacao_Soma_Algarismo extends Activity {
	public String tabela = "";

	public double valor_bem = 0;
	public double valor_residual = 0;
	public double vida_util = 0;

	public double DSA = 0;
	public double acumulada = 0;
	public double res = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.depreciacao_soma_algarismo);

		// TODO Put your code here

		Button tabela = (Button) findViewById(R.id.depreTab);
		tabela.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				EditText Valor = (EditText) findViewById(R.id.valor_bem);
				valor_bem = Double.parseDouble(Valor.getText().toString());

				EditText residual = (EditText) findViewById(R.id.valor_resi);
				valor_residual = Double.parseDouble(residual.getText()
						.toString());

				EditText vida = (EditText) findViewById(R.id.num_anos);
				vida_util = Double.parseDouble(vida.getText().toString());
				conta();
				enviatable();

			}
		});

	}

	public void enviatable() {
		Intent intent = new Intent(this,
				Tabela_Depreciacao_Soma_Algarismo.class);
		intent.putExtra("html", tabela);
		startActivity(intent);
	}

	public void conta() {
		for (int x = 0; x <= vida_util; x++) {
			if (x == 0) {
				tabela += "<tr>" + "<td width='75' nowrap='nowrap'>"
						+ "<p style='text-align: center'>0</p>" + "</td>"
						+ "<td width='164' nowrap='nowrap'>"
						+ "<p style='text-align: center'>-x-</p>" + "</td>"
						+ "<td width='180' nowrap='nowrap'>"
						+ "<p style='text-align: center'>-x-</p>" + "</td>"
						+ "<td width='153' nowrap='nowrap'>"
						+ "<p style='text-align: center'>" + valor_bem + "</p>"
						+ "</td>" + "</tr>";
			}

			else {
				DSA = (valor_bem - valor_residual) / vida_util;
				acumulada = acumulada + DSA;
				res = valor_bem - valor_residual;

				tabela += "<tr>" + "<td width='75' nowrap='nowrap'>"
						+ "<p style='text-align: center'>" + x + "</p>"
						+ "</td>" + "<td width='164' nowrap='nowrap'>"
						+ "<p style='text-align: center'>" + DSA + "</p>"
						+ "</td>" + "<td width='180' nowrap='nowrap'>"
						+ "<p style='text-align: center'>" + acumulada + "</p>"
						+ "</td>" + "<td width='153' nowrap='nowrap'>"
						+ "<p style='text-align: center'>" + res + "</p>"
						+ "</td>" + "</tr>";
			}

		}
	}
}
